package com.hzdl.apple.controller.goodCotroll;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.hzdl.apple.service.GoodsService;
import com.hzdl.apple.utils.DruidUtils;
import com.hzdl.apple.utils.HttpUtils;
@WebServlet("/good/*")
public class GoodController extends HttpServlet{
	private GoodsService service;
	private Connection conn;
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		// 把项目路径存储到application中
		service = new GoodsService();
		try {
			conn = DruidUtils.dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		getServletContext().setAttribute("path", getServletContext().getContextPath());
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String baseUri = req.getRequestURI();
		if (baseUri.contains("/goods")) {
			String fileName = req.getParameter("url");
			HttpUtils.forward("goods.jsp", req, resp);
		}
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

}
